from com.atzl.interaction.WindowHall import BillWindow
from com.atzl.ui.NavigationUI import Ui_Form
from PyQt5 import QtCore
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QPropertyAnimation
from com.atzl.common.Win import Windows
from com.atzl.common.StatusCode import StatusCode
from com.atzl.common.ActionStates import ActionStates
from com.atzl.common.UsersMessage import MessagesUsers
from com.atzl.common.PermissionType import PermissionType
from com.atzl.functions.accounting.func.Logs import CheckLogs
from com.atzl.interaction.WindowScalp import ScalpWindow
from com.atzl.interaction.MainCC import MyWindow
from com.atzl.interaction.WindowWronglySend import WronglySendWindow
from com.atzl.interaction.WindowSetOffer import SetOfferWindow
from com.atzl.functions.customerservice.func.WronglySendDataAnalysis import Datacleansing

# 导航窗口交互
class NavigationWindow(QMainWindow, CheckLogs,Datacleansing):  # 继承:QMainWindow, CheckLogs
    def __init__(self):
        QMainWindow.__init__(self)
        # 设置为全局小部件
        self.ui = Ui_Form()
        self.hall = BillWindow()
        self.setoffer = SetOfferWindow()
        self.scalp = ScalpWindow()
        self.my = MyWindow()
        self.wrong = WronglySendWindow()
        self.m_flag = False
        self.ui.setupUi(self)
        global widgets
        widgets = self.ui

        widgets.pushButton_3.clicked.connect(self.close_app)  # 关闭应用程序
        widgets.pushButton_4.clicked.connect(self.showMinimized)  # 窗口最小化
        widgets.pushButton.clicked.connect(self.show_hall)  # 跳转制作账单页面
        widgets.pushButton_2.clicked.connect(self.show_setoffer)  # 跳转设置报价页面
        widgets.pushButton_5.clicked.connect(self.show_scalp)  # 跳转刷单页面
        widgets.pushButton_6.clicked.connect(self.show_cc)  # 跳转工单处理页面
        widgets.pushButton_7.clicked.connect(self.show_wrong) # 跳转错发报表页面

    # 跳转制作账单页面
    def show_wrong(self):
        # 判断用户是否有权限
        if MessagesUsers.PERMISSION_TYPE == PermissionType.SERVICE \
                or MessagesUsers.PERMISSION_TYPE == PermissionType.BOSS:  # 有权限成功跳转
            Windows.WRONG_WIN = self.wrong  # 制作账单页面对象存入公共模块
            self.hide()  # 隐藏导航页面
            Windows.WRONG_WIN.show()  # 显示制作账单页面
            self.logs_in(ActionStates.INTOBILLWIN)  # 回传用户行为
        else:  # 无权限无法跳转
            self.to_message(StatusCode.INSUFFICIENT_PRICILEGES)  # 弹出消息提示框,提示 暂无权限
            self.logs_in(ActionStates.UNINTOBILLWINOFINSUFFICIENTPRICILEGES)  # 回传用户行为

    # 跳转制作账单页面
    def show_hall(self):
        # 判断用户是否有权限
        if MessagesUsers.PERMISSION_TYPE == PermissionType.FINANCE \
                or MessagesUsers.PERMISSION_TYPE == PermissionType.BOSS:  # 有权限成功跳转
            Windows.HALL_WIN = self.hall  # 制作账单页面对象存入公共模块
            Windows.HALL_WIN.get_tablesname()
            self.hide()  # 隐藏导航页面
            Windows.HALL_WIN.show()  # 显示制作账单页面
            Windows.HALL_WIN.show_anim()  # 执行显示制作账单页面出场动画
            self.logs_in(ActionStates.INTOBILLWIN)  # 回传用户行为
        else:  # 无权限无法跳转
            self.to_message(StatusCode.INSUFFICIENT_PRICILEGES)  # 弹出消息提示框,提示 暂无权限
            self.logs_in(ActionStates.UNINTOBILLWINOFINSUFFICIENTPRICILEGES)  # 回传用户行为


    # 跳转设置报价页面
    def show_setoffer(self):
        if MessagesUsers.PERMISSION_TYPE == PermissionType.FINANCE \
                or MessagesUsers.PERMISSION_TYPE == PermissionType.BOSS:  # 有权限成功跳转
            Windows.SETOFFER_WIN = self.setoffer  # 设置报价页面对象存入公共模块
            self.hide()  # 隐藏导航页面
            Windows.SETOFFER_WIN.show()  # 显示设置报价页面
            Windows.SETOFFER_WIN.show_anim()  # 执行显示设置报价页面出场动画
            self.logs_in(ActionStates.INTOSETOFFERWIN)  # 回传用户行为
        else:  # 无权限无法跳转
            self.to_message(StatusCode.INSUFFICIENT_PRICILEGES)  # 弹出消息提示框,提示 暂无权限
            self.logs_in(ActionStates.UNINTOSETOFFERWINOFINSUFFICIENTPRICILEGES)  # 回传用户行为


    # 跳转刷单页面
    def show_scalp(self):
        if MessagesUsers.PERMISSION_TYPE == PermissionType.FINANCE \
                or MessagesUsers.PERMISSION_TYPE == PermissionType.BOSS:  # 有权限成功跳转
            Windows.SCALP_WIN = self.scalp  # 刷单页面对象存入公共模块
            self.hide()  # 隐藏导航页面
            Windows.SCALP_WIN.show()  # 显示刷单页面
            Windows.SCALP_WIN.show_anim()  # 执行显示刷单页面出场动画
            self.logs_in(ActionStates.INTOSCALPWIN)  # 回传用户行为
        else:
            self.to_message(StatusCode.INSUFFICIENT_PRICILEGES)  # 弹出消息提示框,提示 暂无权限
            self.logs_in(ActionStates.UNINTOSCALPWINOFINSUFFICIENTPRICILEGES)  # 回传用户行为


    # 跳转工单处理页面
    def show_cc(self):
        if MessagesUsers.PERMISSION_TYPE == PermissionType.SERVICE \
                or MessagesUsers.PERMISSION_TYPE == PermissionType.BOSS:  # 有权限成功跳转
            Windows.CC_WIN = self.my  # 工单处理页面对象存入公共模块
            self.hide()  # 隐藏导航页面
            Windows.CC_WIN.show()  # 显示工单处理页面
            self.logs_in(ActionStates.INTOCCWIN)  # 回传用户行为
        else:
            self.to_message(StatusCode.INSUFFICIENT_PRICILEGES)  # 弹出消息提示框,提示 暂无权限
            self.logs_in(ActionStates.UNINTOCCWINOFINSUFFICIENTPRICILEGES)  # 回传用户行为


    def mousePressEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton:
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
            event.accept()
            self.setCursor(QCursor(QtCore.Qt.OpenHandCursor))  # 更改鼠标图标


    def mouseMoveEvent(self, QMouseEvent):
        if QtCore.Qt.LeftButton and self.m_flag:
            self.move(QMouseEvent.globalPos() - self.m_Position)  # 更改窗口位置
            QMouseEvent.accept()


    def mouseReleaseEvent(self, QMouseEvent):
        self.m_flag = False
        self.setCursor(QCursor(QtCore.Qt.ArrowCursor))


    def show_anim(self):
        self.anim0 = QPropertyAnimation(self, b"windowOpacity")  # 设置动画对象
        self.anim0.setDuration(50)  # 设置动画时长
        self.anim0.setStartValue(0)  # 设置初始属性，1.0为不透明
        self.anim0.setEndValue(1)  # 设置结束属性，0为完全透明
        # self.anim.finished.connect(self.close)  # 动画结束时，关闭窗口
        self.anim0.start()


    def to_message(self, text):
        Windows.MESSAGE_WIN.set_message(text)


    def close_app(self):
        self.logs_in(ActionStates.CLOSEAPPLICATION)
        self.close()
